package com.focus.xyz.core.utils.prop;

import com.focus.xyz.core.utils.ResourceUtil;

import java.util.Properties;

/**
 * Created by chenmeng on 2016/4/5.
 */
public class ConfigProp {
    Properties properties;
    private static ConfigProp instance;

    private ConfigProp(){

    }

    private static synchronized void syncInit(){
        if(instance == null){
            instance = new ConfigProp();
        }
    }

    public static ConfigProp getInstance(){
        if(instance == null){
            syncInit();
        }
        return instance;
    }

    public String getValue(String key){
        String value = null;
        Properties prop = null;
        try{
            prop = ResourceUtil.loadPropertiesFromClassPath("config.properties");
            if(prop != null){
                Object obj = prop.get(key);
                if(obj != null){
                    value = obj.toString();
                }else{
                    throw new Exception();
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return value;
    }
}
